/*
 * @Author: 高国强 dx_gaogq@dxinfor.com
 * @Date: 2025-08-18 13:41:38
 * @LastEditors: 高国强 dx_gaogq@dxinfor.com
 * @LastEditTime: 2025-08-18 14:05:45
 * @FilePath: \fishcat\vite.config.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
// import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { pxtovw } from "./src/plugins/pxtovw";

// 按需引入 Element Plus 组件
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";

// const pathSrc = path.resolve(__dirname, 'src')
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    host: "0.0.0.0",
    port: 4399,
    proxy: {
      "/api": {
        target: "http://localhost:9090",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, "/api"),
      },
    },
  },
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      imports: ["vue"],
      resolvers: [
        ElementPlusResolver(),
        // 自动导入图标组件
        IconsResolver({ prefix: "Icon" }),
      ],
      dts: fileURLToPath(new URL("./src/auto-imports.d.ts", import.meta.url)),
    }),
    Components({
      resolvers: [
        // 自动注册图标组件
        IconsResolver({ enabledCollections: ["ep"] }),
        ElementPlusResolver(),
      ],
      dts: fileURLToPath(new URL("./src/components.d.ts", import.meta.url)),
    }),
    Icons({ autoInstall: true }),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        api: "modern-compiler", // 消除 sass 版本提示
      },
    },
    postcss: {
      plugins: [pxtovw()],
    },
  },
});
